﻿using System;
using System.Collections.Generic;
using System.Web;
using NhanAi.Entity;
using NhanAi.DAO;
namespace NhanAi.DAO.Mix
{
    public class SubscribingModel
    {
        SubscribingDao daoSub = new SubscribingDao();
        SubscribingExtensionDao daoExt = new SubscribingExtensionDao();
        public void Create(Subscribing o)
        {
            try
            {
                daoSub.Create(o);
                if (o.SubscribingExtensions != null)
                {
                    foreach (SubscribingExtension e in o.SubscribingExtensions)
                    {
                        e.SubscribingId = o.Id;
                        daoExt.Create(e);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void Delete(int subsId)
        {
            try
            {
                daoSub.Delete(subsId);                
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public Subscribing Read(int id)
        {
            Subscribing o = daoSub.Read(id);
            o.SubscribingExtensions = daoExt.ReadByParent(id);
            return o;
        }
    }
}